<template>
  <div class="swAuConductorShort">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="getList"
        @on-load="getList">
        <template slot-scope="scope" slot="menuRight">
<!--          <el-button class="filter-item" type="primary" size="mini" @click="batchBuKuan()">批量补款</el-button>-->
          <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
        </template>
        <template slot-scope="scope" slot="conductorPersonSearch">
          <el-select v-model="searchForm.conductorPersonCode" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in userList"
              :key="index"
              :label="item.nikename"
              :value="item.userCode">
            </el-option>
          </el-select>
        </template>
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
        </template>

        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small"
                     plain @click.stop="prev(scope.row)">预览</el-button>
          <el-button type="text" size="small"
                     v-if="scope.row.isSupPayment==0"
                     plain @click.stop="oneBuKuan(scope.row)">补款</el-button>
          <!-- <el-button type="text" size="small" hidden="true"
                     v-if="scope.row.isSupPayment==1 && scope.row.confirmStatus==0 "
                     plain @click.stop="queren(scope.row)">确认</el-button> -->
        </template>

      </avue-crud>
      <buKuan ref="buKuan" v-if="buKuanDialog"></buKuan>
      <prev ref="prev" v-if="prevDialog"></prev>
      <batchBuKuan ref="batchBuKuan" v-if="batchBuKuanDialog"></batchBuKuan>
    </basic-container>
  </div>
</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import buKuan from './buKuan.vue';
  import prev from './prev.vue';
  import batchBuKuan from './batchBuKuan.vue';

  import {getSysUserToLS, setSearchFiledsEmpty} from "../../../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../../../api/subwayRat/exportSelf";
  import transitUtil from "../../../../../../api/subwayRat/transitUtil";
  import {
    getSwAuConductorShortList, querenSwAuConductorShort,
    shouPiaoYuanBKQRTZ_zhanNeiRYDLCK_option
  } from "../../../../../../api/stationTiecketManager/xianWngCJXXQR/shouPiaoYuanPKCY/shouPiaoYuanBKQRTZ/zhanNeiRYDLCK";
  export default {
    components: {buKuan,prev,batchBuKuan},
    name: 'swAuConductorShort',
    data() {
      return {
        type : 0,
        userList:[],
        buKuanDialog:false,
        prevDialog:false,
        batchBuKuanDialog:false,
        selectKeys:[], //存放对像
        selectKeyVals:[], //存放值
        option: shouPiaoYuanBKQRTZ_zhanNeiRYDLCK_option,
        listLoading: true,
        listLoadingLimit: true,
        searchForm:{},
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : [],
        listLimit : []
      }
    },
    computed: {
    },
    watch: {
    },
    created() {
    },
    mounted() {
      getSysUserToLS({line_code:this.$store.getters.userInfo.lineCode,station_code:this.$store.getters.userInfo.stationCode}).then(res=>{
        this.userList=res.data.data;
      })
    },
    methods: {
      setSearchFiledsEmpty,
      batchBuKuan(){
        if(this.selectKeyVals.length<=0){
          this.$message.warning("请至少选择一条数据操作！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if ( 1 == this.selectKeys[i].isSupPayment){
            this.$message.warning("勾选数据中存在已补款数据！");
            return
          }
        }
        this.batchBuKuanDialog=true;
        let rows=[];
        Object.assign(rows,this.selectKeys);
        this.$nextTick(()=>{
          this.$refs.batchBuKuan.dialogVisible=true;
          this.$refs.batchBuKuan.getList(rows,this);
        })

      },
      oneBuKuan(row){
        this.buKuanDialog=true;
        this.$nextTick(()=>{
          this.$refs.buKuan.dialogVisible=true;
          this.$refs.buKuan.recallShow(row,this);
        })
      },
      queren(row){
        let th=this;
        querenSwAuConductorShort({ids:row.id}).then(res=>{
          if(res.data.code==0){
            th.$message.success("操作成功！");
            th.getList();
          }else{
            th.$message.error("操作失败！");
          }
        })
      },
      prev(row){
        this.prevDialog=true;
        this.$nextTick(()=>{
          this.$refs.prev.dialogVisible=true;
          this.$refs.prev.recallShow(row,this);
        })
      },
      async exportData(){ // 导出
        this.searchForm.pageNo=1;
        this.searchForm.pageSize=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'售票员补款确认通知-站内人员登录查看');
        }else {
          let res=await getSwAuConductorShortList(this.searchForm);
          let data = res.data.data.list;
          exportDataToExcel(data,this.option.column,'售票员补款确认通知-站内人员登录查看');
        }
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        this.searchForm.lineCode=this.$store.getters.userInfo.lineCode;
        this.searchForm.stationCode=this.$store.getters.userInfo.stationCode;
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        getSwAuConductorShortList(this.searchForm).then((response)=>{
          this.list = response.data.data.list;
          this.listLoading = false;
          this.page.total=response.data.data.pageInfo.total;
        });
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      }
    }
  }
</script>
<style lang="scss">
</style>
